/*     */ package com.cr.framework.shiro.web.session;
/*     */ 
/*     */ import com.cr.common.utils.Threads;
/*     */ import java.util.concurrent.ScheduledExecutorService;
/*     */ import java.util.concurrent.TimeUnit;
/*     */ import org.apache.shiro.session.mgt.SessionValidationScheduler;
/*     */ import org.apache.shiro.session.mgt.ValidatingSessionManager;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.beans.factory.annotation.Qualifier;
/*     */ import org.springframework.beans.factory.annotation.Value;
/*     */ import org.springframework.context.annotation.Lazy;
/*     */ import org.springframework.stereotype.Component;
/*     */ 
/*     */ @Component
/*     */ public class SpringSessionValidationScheduler implements SessionValidationScheduler {
/*  25 */   private static final Logger log = LoggerFactory.getLogger(SpringSessionValidationScheduler.class);
/*     */   
/*     */   public static final long DEFAULT_SESSION_VALIDATION_INTERVAL = 3600000L;
/*     */   
/*     */   @Autowired
/*     */   @Qualifier("scheduledExecutorService")
/*     */   private ScheduledExecutorService executorService;
/*     */   
/*     */   private volatile boolean enabled = false;
/*     */   
/*     */   @Autowired
/*     */   @Qualifier("sessionManager")
/*     */   @Lazy
/*     */   private ValidatingSessionManager sessionManager;
/*     */   
/*     */   @Value("${shiro.session.validationInterval}")
/*     */   private long sessionValidationInterval;
/*     */   
/*     */   public boolean isEnabled() {
/*  53 */     return this.enabled;
/*     */   }
/*     */   
/*     */   public void setSessionValidationInterval(long sessionValidationInterval) {
/*  68 */     this.sessionValidationInterval = sessionValidationInterval;
/*     */   }
/*     */   
/*     */   public void enableSessionValidation() {
/*  78 */     this.enabled = true;
/*  80 */     if (log.isDebugEnabled())
/*  82 */       log.debug("Scheduling session validation job using Spring Scheduler with session validation interval of [" + this.sessionValidationInterval + "]ms..."); 
/*     */     try {
/*  88 */       this.executorService.scheduleAtFixedRate(new Runnable() {
/*     */             public void run() {
/*  93 */               if (SpringSessionValidationScheduler.this.enabled)
/*  95 */                 SpringSessionValidationScheduler.this.sessionManager.validateSessions(); 
/*     */             }
/*     */           },  1000L, this.sessionValidationInterval * 60L * 1000L, TimeUnit.MILLISECONDS);
/* 100 */       this.enabled = true;
/* 102 */       if (log.isDebugEnabled())
/* 104 */         log.debug("Session validation job successfully scheduled with Spring Scheduler."); 
/* 108 */     } catch (Exception e) {
/* 110 */       if (log.isErrorEnabled())
/* 112 */         log.error("Error starting the Spring Scheduler session validation job.  Session validation may not occur.", e); 
/*     */     } 
/*     */   }
/*     */   
/*     */   public void disableSessionValidation() {
/* 120 */     if (log.isDebugEnabled())
/* 122 */       log.debug("Stopping Spring Scheduler session validation job..."); 
/* 125 */     if (this.enabled)
/* 127 */       Threads.shutdownAndAwaitTermination(this.executorService); 
/* 129 */     this.enabled = false;
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-framework-4.7.0.jar!\com\cr\framework\shiro\web\session\SpringSessionValidationScheduler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */